﻿/// <reference path="../../../../Scripts/jquery-1.7.1.min.js" />
var ObjectIneed = new function () {
    this.TagListIneed = "#list-ineed";
    this.TagItemIneed = ".item-ineed";
    this.TagPanelItemIneed = "#panel-list-item-need"
    this.TagItemIneedDislay = ".item-ineed-dislay";
    this.TagDescriptionItemIneed = "#panel-list-content-item-need";
    this.TagCloseDesriptionItemIneed = "#close-content-item-ineed";
    this.TagListContentItem = "#list-content-item-ineed";
    this.TagContentItemDisplay = ".panel-content-item-ineed";
    this.TagContentItemDisplayActive = ".panel-content-item-ineed-active";
    this.tagUpdate = "#TagUpdateIneed";
    this.TagUpdateContentIneed = ".list-panel-cotent-item-need";
    this.TagUpdatePreview = ".list-item-ineed";
    this.TagScriptUpdate = ".script-select-item";
    this.TagImageLoading = ".imgLoading"
    this.TagHeadPostRequest = "#head-ineed";
    this.ClassContentItemDisplayActive = "panel-content-item-ineed-active";
    this.ClassDislay = "item-ineed-dislay";


    this.Height = 65;
    this.ColorEnable = "#D23640";
    this.ColorDisable = "#d0d0d0";
    this.TagPrev = "#prev-ineed";
    this.TagNext = "#next-ineed";
    this.installed = function () {
        $(ObjectIneed.TagImageLoading).hide();
        $(ObjectIneed.TagDescriptionItemIneed).hide();
        $(ObjectIneed.TagPrev).css('color', ObjectIneed.ColorDisable);
        //ObjectIneed.Height = $(ObjectIneed.TagItemIneed).height();
        $(ObjectIneed.TagListIneed).css({ 'position': 'relative', 'height': ObjectIneed.Height * 5 + 20 + "px", 'overflow': 'hidden' });
        $(ObjectIneed.TagPanelItemIneed).css({ 'position': 'absolute' });
        $(ObjectIneed.TagItemIneed).each(function () {
            $(this).css('opacity', '0');
        })
        if ($(ObjectIneed.TagItemIneed).length > 5) {
            for (var i = 0; i < 5; i++) {
                $(ObjectIneed.TagItemIneed).eq(i).addClass("item-ineed-dislay");
                $(ObjectIneed.TagItemIneed).eq(i).css('opacity', '1');
            }
        }
        else
            $(ObjectIneed.TagItemIneed).each(function () {
                $(this).addClass("item-ineed-dislay");
                $(this).css('opacity', '1');
            })
    }
    this.UpdateInstalled = function () {
        // action select item i need
        $(ObjectIneed.TagItemIneed).click(function (event) {
            $(ObjectIneed.TagDescriptionItemIneed).show();
            $(ObjectIneed.TagCloseDesriptionItemIneed).show();
            $(ObjectIneed.TagListContentItem).show();
            $(ObjectIneed.TagContentItemDisplayActive).removeClass(ObjectIneed.ClassContentItemDisplayActive);
            $('#' + $(this).attr("title")).addClass(ObjectIneed.ClassContentItemDisplayActive);
            fleXenv.fleXcrollMain($(this).attr("title"));
            return false;
        })
    }
    this.OnSuccess = function (data) {
        if (jQuery.trim(data.responseText.toString()) != "") {
            $(ObjectIneed.TagListContentItem).append($(ObjectIneed.TagUpdateContentIneed).html());
            $(ObjectIneed.TagPanelItemIneed).append($(ObjectIneed.TagUpdatePreview).html());
            //$('head').append($(ObjectIneed.TagScriptUpdate).html());
            $(ObjectIneed.tagUpdate).html("")
            $(ObjectIneed.TagNext).attr('href', $(ObjectIneed.TagNext).attr('href').substring(0, $(ObjectIneed.TagNext).attr('href').lastIndexOf("=") + 1) + $(ObjectIneed.TagItemIneed + ':last').attr('title').substring($(ObjectIneed.TagItemIneed + ':last').attr('title').lastIndexOf("-") + 1, $(ObjectIneed.TagItemIneedDislay + ':last').attr('title').length + 1));
            $(ObjectIneed.TagPrev).show();
            $(ObjectIneed.TagNext).show();
            $(ObjectIneed.TagImageLoading).hide();
            ObjectIneed.UpdateInstalled();
        }
        else {
            $(ObjectIneed.TagNext).attr('href', '#');
            $(ObjectIneed.TagPrev).show();
            $(ObjectIneed.TagNext).show();
            $(ObjectIneed.TagImageLoading).hide();
            ObjectIneed.UpdateInstalled();
        }
    }
    this.PostIneed = function (data) {

    }
    this.PostIneedBegin = function () {
        if ($(ObjectIneed.TagHeadPostRequest).children('form').children('input[name="Title"]').val() == "") {
            return false; 
        }
    }
}
$(document).ready(function () {
    // action next
    $(ObjectIneed.TagNext).click(function () {
        if ($(ObjectIneed.TagItemIneedDislay + ':last').index() < $(ObjectIneed.TagItemIneed + ':last').index()) {
            $(ObjectIneed.TagItemIneedDislay).each(function () {
                $(this).css('opacity', '1');
            })
            $(ObjectIneed.TagItemIneedDislay + ':last').next().addClass(ObjectIneed.ClassDislay);
            $(ObjectIneed.TagPanelItemIneed).animate({ 'top': '-=' + ObjectIneed.Height }, function () {
                $(ObjectIneed.TagItemIneedDislay + ':last').animate({ 'opacity': '1' });
                $(ObjectIneed.TagItemIneedDislay + ':first').css('opacity', '0');
                $(ObjectIneed.TagItemIneedDislay + ':first').removeClass(ObjectIneed.ClassDislay);
                if ($(ObjectIneed.TagItemIneed + ':last').index() == $(ObjectIneed.TagItemIneedDislay + ':last').index())
                    $(ObjectIneed.TagNext).css('color', ObjectIneed.ColorDisable);
                if ($(ObjectIneed.TagItemIneedDislay + 'first').index() != $(ObjectIneed.TagItemIneed + ':first').index())
                    $(ObjectIneed.TagPrev).css('color', ObjectIneed.ColorEnable);
            });
        }
        else
            return false;
        var LastIndexTagA = $(ObjectIneed.TagItemIneedDislay + ':last').attr('title').substring($(ObjectIneed.TagItemIneedDislay + ':last').attr('title').lastIndexOf("-") + 1, $(ObjectIneed.TagItemIneedDislay + ':last').attr('title').length);
        var StartId = $(this).attr('href').substring($(this).attr('href').lastIndexOf("=") + 1, $(this).attr('href').length);
        if ($(ObjectIneed.TagItemIneedDislay + ':last').index() < $(ObjectIneed.TagItemIneed + ':last').index() - 3) {
            return false;
        }
        if ($(ObjectIneed.TagNext).attr('href') == "#") return false;
        $(ObjectIneed.TagPrev).hide();
        $(ObjectIneed.TagNext).hide();
        $(ObjectIneed.TagImageLoading).show();

    })

    // action prev
    $(ObjectIneed.TagPrev).click(function () {
        if ($(ObjectIneed.TagItemIneed + ':first').index() != $(ObjectIneed.TagItemIneedDislay + ':first').index()) {
            $(ObjectIneed.TagItemIneedDislay).each(function () {
                $(this).css('opacity', '1');
            })
            $(ObjectIneed.TagItemIneedDislay + ':first').prev().addClass(ObjectIneed.ClassDislay);
            $(ObjectIneed.TagPanelItemIneed).animate({ 'top': '+=' + ObjectIneed.Height }, function () {
                $(ObjectIneed.TagItemIneedDislay + ':first').animate({ 'opacity': '1' });
                $(ObjectIneed.TagItemIneedDislay + ':last').css('opacity', '0');
                $(ObjectIneed.TagItemIneedDislay + ':last').removeClass(ObjectIneed.ClassDislay);
                if ($(ObjectIneed.TagItemIneed + ':first').index() == $(ObjectIneed.TagItemIneedDislay + ':first').index())
                    $(ObjectIneed.TagPrev).css('color', ObjectIneed.ColorDisable);
                if ($(ObjectIneed.TagItemIneed + ':last').index() != $(ObjectIneed.TagItemIneedDislay + ':last').index())
                    $(ObjectIneed.TagNext).css('color', ObjectIneed.ColorEnable);
            })
        }
        return false;
    })

    // action select item i need
    $(ObjectIneed.TagItemIneed).click(function (event) {
        $(ObjectIneed.TagDescriptionItemIneed).show();
        $(ObjectIneed.TagCloseDesriptionItemIneed).show();
        $(ObjectIneed.TagListContentItem).show();
        $(ObjectIneed.TagContentItemDisplayActive).removeClass(ObjectIneed.ClassContentItemDisplayActive);
        $('#' + $(this).attr("title")).addClass(ObjectIneed.ClassContentItemDisplayActive);
        fleXenv.fleXcrollMain($(this).attr("title"));
        return false;
    })

    // action close description item i need
    $(ObjectIneed.TagCloseDesriptionItemIneed).click(function () {
        $(ObjectIneed.TagDescriptionItemIneed).hide();
        $(ObjectIneed.TagListContentItem).show();
        $(this).hide();
        return false;
    })


})
